﻿/*
 * This software is the confidential and proprietary
 * information of NetBay
 * Such confidential information should not be disclosed
 * NetBay copyright(c) 2010
 */

#region Using
using System;
using System.Windows.Forms;
using System.Collections;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using NetBay.Core.Log;
#endregion



namespace NetBay.Core.Tools
{
    /// <summary>
    /// 
    /// </summary>
    public static class StringSerializer
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="treeView"></param>
        /// <returns></returns>
        public static Byte[] Serialize(TreeView p_oTreeView)
        {
            Byte[] l_aRet = new Byte[0];
            try
            {
                ArrayList l_aListeNoeuds = new ArrayList();
                foreach (TreeNode l_oNoeud in (p_oTreeView.Nodes))
                {
                    l_aListeNoeuds.Add(l_oNoeud);
                }

                BinaryFormatter l_oSerializer = new BinaryFormatter();
                MemoryStream l_oMemoryStream = new MemoryStream();
                l_oSerializer.Serialize(l_oMemoryStream, l_aListeNoeuds); 

                l_aRet = l_oMemoryStream.ToArray();
            }
            catch (Exception ex)
            {
                LogManager.Instance().LogErrorFormat(
                     ex,
                     "Failed to serilize TreeView: {0}", p_oTreeView.ToString());
            }

            return l_aRet;
        }


        public static void Deserialize(TreeView p_oTreeView, Byte[] p_aToRead)
        {
        }
    }
}
